package com.bilibili.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bilibili.dao.UserCoinMapper;
import com.bilibili.domain.entity.UserCoin;
import com.bilibili.service.UserCoinService;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
* @author www
* @description 针对表【t_user_coin(用户硬币表)】的数据库操作Service实现
* @createDate 2024-06-17 19:39:54
*/
@Service
public class UserCoinServiceImpl extends ServiceImpl<UserCoinMapper, UserCoin>
    implements UserCoinService {

    //TODO:可以添加一些权限,用户获取硬币等业务

    @Resource
    private UserCoinMapper userCoinMapper;

    LambdaQueryWrapper<UserCoin> wrapper = new LambdaQueryWrapper<>();

    @Override
    public UserCoin getUserCoinsAmount(Long userId) {
        wrapper.eq(UserCoin::getUserId,userId);
        return userCoinMapper.selectOne(wrapper);
    }

    @Override
    public void updateCoinsAmount(Long userId, long userCoinAmount) {
        wrapper.eq(UserCoin::getUserId,userId);
        UserCoin userCoin = userCoinMapper.selectOne(wrapper);
        userCoin.setAmount(userCoinAmount);
        userCoin.setUpdateTime(new Date());

        userCoinMapper.update(userCoin,null);
    }
}




